<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>prencar: D:/Workspace/Arduino/prencar/LineFollow.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="prencar.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">prencar
   &#160;<span id="projectnumber">1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_line_follow_8cpp.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">D:/Workspace/Arduino/prencar/LineFollow.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_line_follow_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;Arduino.h&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="_line_follow_8h.html">LineFollow.h</a>&quot;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;<a class="code" href="_move_8h.html">Move.h</a>&quot;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;<a class="code" href="_configuration_8h.html">Configuration.h</a>&quot;</span>
<a name="l00005"></a>00005 
<a name="l00009"></a><a class="code" href="class_line_follow.html#ace2e49549627ad0682ed71e0be714086">00009</a> <a class="code" href="class_line_follow.html#ace2e49549627ad0682ed71e0be714086">LineFollow::LineFollow</a>()
<a name="l00010"></a>00010 {
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 }
<a name="l00013"></a>00013 
<a name="l00019"></a><a class="code" href="class_line_follow.html#afac0ad1ff185b7e5f9b47428cb2e5e48">00019</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#afac0ad1ff185b7e5f9b47428cb2e5e48">LineFollow::begin</a>(){
<a name="l00020"></a>00020   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a> = <a class="code" href="class_communication.html#ad7b13fccf78bfce83efc9bb06c64facd">Communication::getInstance</a>();
<a name="l00021"></a>00021   <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a> = <a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">Move::getInstance</a>();
<a name="l00022"></a>00022   <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a> = <a class="code" href="class_configuration.html#ae327d26e81014cf46b25802478fe9b8e">Configuration::getInstance</a>();
<a name="l00023"></a>00023 
<a name="l00024"></a>00024   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>, INPUT);
<a name="l00025"></a>00025   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>, INPUT);
<a name="l00026"></a>00026   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>, INPUT);
<a name="l00027"></a>00027   pinMode(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>, INPUT);
<a name="l00028"></a>00028 
<a name="l00029"></a>00029   <span class="comment">//make sure, the pull up resistors are off</span>
<a name="l00030"></a>00030   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>, LOW);
<a name="l00031"></a>00031   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>, LOW);
<a name="l00032"></a>00032   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>, LOW);
<a name="l00033"></a>00033   digitalWrite(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>, LOW);
<a name="l00034"></a>00034 
<a name="l00035"></a>00035   <a class="code" href="class_line_follow.html#a48dac746e582df53a191bbb6f6c9ef28">hasReachedLine</a> = <span class="keyword">false</span>;
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 
<a name="l00041"></a><a class="code" href="class_line_follow.html#a5f3e76e795bacff24be60b7f65d84d94">00041</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a5f3e76e795bacff24be60b7f65d84d94">LineFollow::startIt</a>(){
<a name="l00042"></a>00042   <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a> = 0;
<a name="l00043"></a>00043   <a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7" title="todo: write comment">_sensoralt</a> = 20;
<a name="l00044"></a>00044   <a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d" title="todo: write comment">_deltaPWM</a> = 0;
<a name="l00045"></a>00045   <a class="code" href="class_line_follow.html#a00b50369d005edbfe81937c77713cf8c">_timeSinceCorrectionStarted</a> = 0;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047   <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a>-&gt;<a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">controlMotors</a>(<a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a24e118088874b8f9d56bcaf245f1461d" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedLeft</a>, <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aabc113e529eb659768ca98f15d3952a3" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedRight</a>);
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00069"></a><a class="code" href="class_line_follow.html#a93ff35747f2ae3bb26998f07243afc3c">00069</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a93ff35747f2ae3bb26998f07243afc3c">LineFollow::doJob</a>(){
<a name="l00070"></a>00070   <span class="keywordtype">int</span> sensorValues[2];
<a name="l00071"></a>00071   <a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">readFrontLineSensors</a>(sensorValues);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073   <span class="comment">/*</span>
<a name="l00074"></a>00074 <span class="comment">  //This statements are just to see if we can make the car moving straight forward.</span>
<a name="l00075"></a>00075 <span class="comment">   _move-&gt;controlMotors(forward, _conf-&gt;lineFollowInitialSpeed, forward, _conf-&gt;lineFollowInitialSpeed + 5);</span>
<a name="l00076"></a>00076 <span class="comment">   delay(5000);</span>
<a name="l00077"></a>00077 <span class="comment">   _move-&gt;performFastStop();*/</span>
<a name="l00078"></a>00078 
<a name="l00079"></a>00079   <span class="comment">//check if a 90° curve is needed</span>
<a name="l00080"></a>00080   <span class="keywordflow">if</span>(sensorValues[0] &lt; <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a>){
<a name="l00081"></a>00081     <span class="comment">//_com-&gt;sendString(&quot;fast stop should be done now.&quot;);</span>
<a name="l00083"></a>00083 <span class="comment"></span>    <span class="comment">/*_com-&gt;send(55, sensorValues[0]);</span>
<a name="l00084"></a>00084 <span class="comment">     _move-&gt;performFastStop();</span>
<a name="l00085"></a>00085 <span class="comment">     hasReachedLine = true;</span>
<a name="l00086"></a>00086 <span class="comment">     return;*/</span>
<a name="l00087"></a>00087   }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089   <span class="comment">//Check - if a correction (driving a courve to get back to the line) is in progress - if it&#39;s already time to drive</span>
<a name="l00090"></a>00090   <span class="comment">//straight forward again.</span>
<a name="l00091"></a>00091   <span class="comment">/*if(_timeSinceCorrectionStarted != 0 &amp;&amp; millis() &gt;= _timeSinceCorrectionStarted + _conf-&gt;lineCorrectionDuration){</span>
<a name="l00092"></a>00092 <span class="comment">   //    _com-&gt;sendString(&quot;after correction - moving forward again&quot;);</span>
<a name="l00093"></a>00093 <span class="comment">   _move-&gt;controlMotors(forward, _conf-&gt;lineFollowInitialSpeed, forward, _conf-&gt;lineFollowInitialSpeed);</span>
<a name="l00094"></a>00094 <span class="comment">   _timeSinceCorrectionStarted = 0;</span>
<a name="l00095"></a>00095 <span class="comment">   }*/</span>
<a name="l00096"></a>00096 
<a name="l00097"></a>00097   <span class="comment">//Read the line sensor values to check if one line sensor has detected white ground which means that a</span>
<a name="l00098"></a>00098   <span class="comment">//correction is needed. If so a correction will be started.</span>
<a name="l00099"></a>00099   <span class="comment">//We do this only if no correction is in progress</span>
<a name="l00100"></a>00100   <span class="comment">//_com-&gt;send(_timeSinceCorrectionStarted);</span>
<a name="l00101"></a>00101   <span class="keywordflow">if</span>(<a class="code" href="class_line_follow.html#a00b50369d005edbfe81937c77713cf8c">_timeSinceCorrectionStarted</a> == 0){
<a name="l00102"></a>00102     <a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">readLineSensors</a>(sensorValues);
<a name="l00103"></a>00103 
<a name="l00104"></a>00104     <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a> = sensorValues[0]-sensorValues[1];
<a name="l00105"></a>00105     <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(3,<a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a>);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107     <a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d" title="todo: write comment">_deltaPWM</a> = <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aabaf837f8816911a6d0b1e8cd7867cb9">lineFollowKp</a> * (<a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a>/100) + (<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aad2572d8c68520c2ef6613d29f38a9cf">lineFollowKd</a>/100) * (<a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a>-<a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7" title="todo: write comment">_sensoralt</a>);
<a name="l00108"></a>00108     <a class="code" href="class_line_follow.html#ae28a165a4eaf1ab88fe0cab11e325ba7" title="todo: write comment">_sensoralt</a> = <a class="code" href="class_line_follow.html#a44ff5bd13460ce3d6737319c6d0023f0" title="todo: write comment">_deltasensor</a>;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110     <a class="code" href="class_line_follow.html#ac6fe17d43571248ea2e74fade7ceb5bd" title="The reference to the move class to control the motors.">_move</a>-&gt;<a class="code" href="class_move.html#a5ba1c7d78d6a067bc3cfa5f9cdca921f">changeMotorSpeedBasedOnInitialSpeed</a>(<a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d" title="todo: write comment">_deltaPWM</a>,(-1)*<a class="code" href="class_line_follow.html#aaef3837f6fd0ea4d69458dbe7a5ed54d" title="todo: write comment">_deltaPWM</a>); 
<a name="l00111"></a>00111     <span class="comment">//_timeSinceCorrectionStarted = millis(); </span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     <span class="comment">/*{</span>
<a name="l00116"></a>00116 <span class="comment">     //    _com-&gt;sendString(&quot;check line sensors&quot;);</span>
<a name="l00117"></a>00117 <span class="comment">     readLineSensors(sensorValues);</span>
<a name="l00118"></a>00118 <span class="comment">     </span>
<a name="l00119"></a>00119 <span class="comment">     //left sensor</span>
<a name="l00120"></a>00120 <span class="comment">     if(sensorValues[0] &lt; _conf-&gt;lineFollowWhiteThreshold){</span>
<a name="l00121"></a>00121 <span class="comment">     _com-&gt;sendString(&quot;korrigiere nach rechts.&quot;);</span>
<a name="l00122"></a>00122 <span class="comment">     _move-&gt;changeMotorSpeed(((-1)*((int)_conf-&gt;lineFollowCorrectionMinus)), ((int)_conf-&gt;lineFollowCorrectionPlus));</span>
<a name="l00123"></a>00123 <span class="comment">     _timeSinceCorrectionStarted = millis();</span>
<a name="l00124"></a>00124 <span class="comment">     _com-&gt;send(56, sensorValues[0]);</span>
<a name="l00125"></a>00125 <span class="comment">     }</span>
<a name="l00126"></a>00126 <span class="comment">     </span>
<a name="l00127"></a>00127 <span class="comment">     //right sensor</span>
<a name="l00128"></a>00128 <span class="comment">     if(sensorValues[1] &lt; _conf-&gt;lineFollowWhiteThreshold){</span>
<a name="l00129"></a>00129 <span class="comment">     _com-&gt;sendString(&quot;korrigiere nach links.&quot;);</span>
<a name="l00130"></a>00130 <span class="comment">     _move-&gt;changeMotorSpeed(((int)_conf-&gt;lineFollowCorrectionPlus), ((-1)*((int)_conf-&gt;lineFollowCorrectionMinus)));</span>
<a name="l00131"></a>00131 <span class="comment">     _timeSinceCorrectionStarted = millis();</span>
<a name="l00132"></a>00132 <span class="comment">     _com-&gt;send(57, sensorValues[1]);</span>
<a name="l00133"></a>00133 <span class="comment">     }*/</span>
<a name="l00134"></a>00134   }
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 
<a name="l00143"></a><a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">00143</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a1e3bb3e01044c86e7ad87c632bac6634">LineFollow::readFrontLineSensors</a>(<span class="keywordtype">int</span>* resultArray){
<a name="l00144"></a>00144 
<a name="l00145"></a>00145   resultArray[0] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00147"></a>00147   resultArray[1] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#ab8d7a8d9f62cfafe082cc32915ef4bfa">lineFollowRightFrontSensorPin</a>);
<a name="l00148"></a>00148 
<a name="l00149"></a>00149   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(1, resultArray, 2);
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00156"></a><a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">00156</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#af85fe355ee0699cabc3c817d10aa8b9d">LineFollow::readLineSensors</a>(<span class="keywordtype">int</span>* resultArray){
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   resultArray[0] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a09d83c2f3c4485fd864bf998e62788d7">lineFollowLeftSensorPin</a>);
<a name="l00160"></a>00160   resultArray[1] = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a254b7ac19c994603776d47645235a132">lineFollowRightSensorPin</a>);
<a name="l00161"></a>00161 
<a name="l00162"></a>00162   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(2, resultArray, 2);
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00186"></a><a class="code" href="class_line_follow.html#a9db172747e4457a6b01f8d27ed41ac39">00186</a> <span class="keywordtype">void</span> <a class="code" href="class_line_follow.html#a9db172747e4457a6b01f8d27ed41ac39" title="Calibrates the sensors.">LineFollow::calibrateSensors</a>(){
<a name="l00187"></a>00187   <span class="keywordtype">float</span> sensorValue;
<a name="l00188"></a>00188   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(200);
<a name="l00189"></a>00189   delay(10000);
<a name="l00190"></a>00190   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(201);
<a name="l00191"></a>00191 
<a name="l00192"></a>00192   <span class="comment">//sensor measurement on black ground</span>
<a name="l00193"></a>00193   <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> = 1023;
<a name="l00194"></a>00194   <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a> = 0;
<a name="l00195"></a>00195   <span class="keywordflow">for</span>(byte i = 0; i &lt; 50; i++){
<a name="l00196"></a>00196     sensorValue = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00197"></a>00197     <span class="keywordflow">if</span>(sensorValue &lt; <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a>){
<a name="l00198"></a>00198       <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> = sensorValue;
<a name="l00199"></a>00199     }
<a name="l00200"></a>00200     <span class="keywordflow">if</span>(sensorValue &gt; <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a>){
<a name="l00201"></a>00201       <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a> = sensorValue;
<a name="l00202"></a>00202     }
<a name="l00203"></a>00203     delay(100);
<a name="l00204"></a>00204   }
<a name="l00205"></a>00205 
<a name="l00206"></a>00206   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(202);
<a name="l00207"></a>00207   delay(10000);
<a name="l00208"></a>00208   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(201);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210   <span class="comment">//sensor measurement on white ground</span>
<a name="l00211"></a>00211   <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a> = 1023;
<a name="l00212"></a>00212   <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a> = 0;
<a name="l00213"></a>00213   <span class="keywordflow">for</span>(byte i = 0; i &lt; 50; i++){
<a name="l00214"></a>00214     sensorValue = analogRead(<a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a683b496d15eca4addb13325d9707abcf">lineFollowLeftFrontSensorPin</a>);
<a name="l00215"></a>00215     <span class="keywordflow">if</span>(sensorValue &lt; <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a>){
<a name="l00216"></a>00216       <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a> = sensorValue;
<a name="l00217"></a>00217     }
<a name="l00218"></a>00218     <span class="keywordflow">if</span>(sensorValue &gt; <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>){
<a name="l00219"></a>00219       <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a> = sensorValue;
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221     delay(100);
<a name="l00222"></a>00222   }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224   <span class="comment">//calculate the white threshold value</span>
<a name="l00225"></a>00225   <span class="keywordtype">int</span> rangeWhiteMaxToBlackMin = <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a> - <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>;
<a name="l00226"></a>00226   <span class="comment">//calculate 1/3 out of the range and add it to the whiteMax. This will be the new whiteThreshold value.</span>
<a name="l00227"></a>00227   <span class="comment">//(We know that the calculation doesn&#39;t use float even though a division is made here.)</span>
<a name="l00228"></a>00228   <span class="keywordtype">int</span> oneThirdOfRange = rangeWhiteMaxToBlackMin/3;
<a name="l00229"></a>00229   <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a> = _calibrationSensorWhiteMax + oneThirdOfRange;
<a name="l00230"></a>00230 
<a name="l00231"></a>00231   <span class="keywordtype">int</span> measurements[] = {
<a name="l00232"></a>00232     <a class="code" href="class_line_follow.html#aeb722614b85d484aafe0714f9d319f3e" title="Holds the minimum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMin</a>, <a class="code" href="class_line_follow.html#aaeea70b897deb0295401aa316189c2ba" title="Holds the maximum value that was measured during the calibration for &quot;black&quot;.">_calibrationSensorBlackMax</a>, <a class="code" href="class_line_follow.html#a6f7f1f6ff879d0ce76823b03844bfc9a" title="Holds the minimum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMin</a>, <a class="code" href="class_line_follow.html#a7b4f3695a0133e9ba170199ddb1bdde6" title="Holds the maximum value that was measured during the calibration for &quot;white&quot;.">_calibrationSensorWhiteMax</a>,
<a name="l00233"></a>00233     oneThirdOfRange, <a class="code" href="class_line_follow.html#a0112816d723edd82daf2dabbf1ff074f" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a6c0d6f8b78ea6b6e167c80bce9447906" title="Threshold value from black to white.">lineFollowWhiteThreshold</a>
<a name="l00234"></a>00234   };
<a name="l00235"></a>00235 
<a name="l00236"></a>00236   <a class="code" href="class_line_follow.html#a8c494126e578f00240532b866b051718" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(203, measurements, 6);
<a name="l00237"></a>00237 }
<a name="l00238"></a>00238 
<a name="l00239"></a>00239 
<a name="l00240"></a>00240 
<a name="l00241"></a>00241 
<a name="l00242"></a>00242 
<a name="l00243"></a>00243 
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 
<a name="l00246"></a>00246 
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 
<a name="l00255"></a>00255 
<a name="l00256"></a>00256 
<a name="l00257"></a>00257 
<a name="l00258"></a>00258 
<a name="l00259"></a>00259 
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 
<a name="l00262"></a>00262 
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_line_follow_8cpp.html">LineFollow.cpp</a>      </li>

    <li class="footer">Generated on Tue Apr 3 2012 18:43:12 for prencar by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
